package com.zgz.underwrite.action;

import java.util.Collections;
import java.util.List;

import com.zgz.underwrite.dao.EmployeeDao;
import com.zgz.underwrite.model.Employee;

public class EmployeeAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1017429536983973531L;

	private Employee emp;
	private EmployeeDao empDao;
	
	public String newEmp(){
		try {
			this.empDao.save(this.emp);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return INPUT;
	}
	
	public String deleteEmp(){
		try {
			this.empDao.delete(this.emp);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	public String findAllEmp(){
		List<Employee> emps = Collections.emptyList();
		try {
			emps = (List<Employee>) this.empDao.getAll();
			super.request.setAttribute("emps", emps);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}
	
	public String editEmp(){
		try {
			this.empDao.update(this.emp);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return INPUT;
	}
	
	
	public void setEmp(Employee emp) {
		this.emp = emp;
	}
	public Employee getEmp() {
		return emp;
	}
	public void setEmpDao(EmployeeDao empDao) {
		this.empDao = empDao;
	}
	public EmployeeDao getEmpDao() {
		return empDao;
	}
	
	
}
